﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditOrder.aspx.cs" Inherits="Truextend.CoffeShop.Layouts.Truextend.CoffeShop.EditOrder" DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    
    <center><h2>Edit Order</h2></center>
                
    <center><table>
        <tr>
            <td>
                <asp:Label ID="LblTitle" runat="server" Text="Title: "></asp:Label>
            </td>
            <td>
                <asp:Label ID="LblTitleContent" runat="server" ></asp:Label>
            </td>
        </tr>  

        <tr>
            <td>
                <asp:Label ID="LblRestaurant" runat="server" Text="Restaurant: "></asp:Label>
            </td>
            <td>
                <asp:Label ID="LblRestaurantContent" runat="server" ></asp:Label>
            </td>

        </ tr>                            
                            
        <tr>
            <td colspan="2">

                <div runat="server" ID="DivOptions" visible="true">
                    <center><asp:GridView ID="OptionsGridView" runat="server" AutoGenerateColumns="False" 
                    EnableModelValidation="True" DataKeyNames="OptionID">            
                        <Columns>
                            <asp:TemplateField HeaderText="OptionID" Visible="False">
                                <ItemTemplate>
                                    <asp:Label ID="LblOptionID" runat="server" Text='<%# Bind("OptionID") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="TxBxOptionID" runat="server" Text='<%# Bind("OptionID") %>'></asp:TextBox>
                                </EditItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField SortExpression="CheckBoxOption">
                                <ItemTemplate>
                                    <asp:CheckBox ID="CheckBoxOption" runat="server"
                                        Checked='<%# Bind("CheckBoxOption") %>' Enabled="true" />
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:CheckBox ID="CheckBoxOption" runat="server" 
                                        Checked='<%# Bind("CheckBoxOption") %>' />
                                </EditItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Product" SortExpression="Description">                
                                <EditItemTemplate>
                                    <asp:TextBox ID="TxBxDescripion" runat="server" Text='<%# Bind("Description") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="LblDescription" runat="server" Text='<%# Bind("Description") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Price" SortExpression="Price">                
                                <EditItemTemplate>
                                    <asp:TextBox ID="TxBxPrice" runat="server" Text='<%# Bind("Price") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="LblPrice" runat="server"  Text='<%# Bind("Price") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>

                            <asp:TemplateField HeaderText="Quantity" SortExpression="Quantity">                
                                <EditItemTemplate>
                                    <asp:TextBox ID="TxBxAmount" runat="server" Text='<%# Bind("Amount") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:TextBox ID="TxBxAmount" runat="server" Enabled='<%# Bind("AmountState") %>' Text='<%# Bind("Amount") %>' ></asp:TextBox>
                                </ItemTemplate>
                            </asp:TemplateField>
                                
                        </Columns>        
                    </asp:GridView></center>     
                </div>           
                                    
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="LblTotalPrice" runat="server" Text="Total Cost: "></asp:Label>
            </td>
            <td>
                <asp:Label ID="LblTotalPriceContent" runat="server"></asp:Label>
                <asp:HiddenField ID="HideTotalPrice" runat="server" />
            </td>
        </tr>        
                            
        <tr>
            <td align="left">
                <asp:HyperLink ID="HLReturn" runat="server" NavigateUrl="~/CoffeeShop/SitePages/Home.aspx">Go Back</asp:HyperLink>                    
            </td>
            <td align="right">
                <asp:Button ID="BtnRegisterPersonalOrder" OnClick="BtnRegisterPersonalOrder_Click" runat="server" Text="Edit" />
            </td>
        </tr>
            
    </table></center>    

    <script type="text/javascript">
        $(document).ready(function () {

            $('tr tr td input:checkbox').click(function () {
                if ($(this).is(':checked')) {

                    var total_cost = 0;

                    $('tr tr').filter(function () { return $('td input:checkbox:checked', this).length }).each(function () {
                        $('td input:text', this).attr('disabled', false);
                    })  

                } else {
                    $('tr tr').filter(function () { return $('td input:checkbox:not(:checked)', this).length }).each(function () {
                        $('td input:text', this).attr('disabled', true);
                    })
                }
            })

            $('tr tr td input:checkbox').click(function () {

                var total_cost = 0;

                $('tr tr').filter(function () { return $('td input:checkbox:checked', this).length }).each(function () {
                    total_cost = total_cost + ($('td input:text', this).val() * $('span[id$="LblPrice"]', this).text());
                })

                $('#<%= LblTotalPriceContent.ClientID  %>').html(total_cost);
                $('#<%= HideTotalPrice.ClientID  %>').val(total_cost);

            });

            $('td tr input:text[id$="TxBxAmount"]').keyup(function (event) {

                var total_cost = 0;

                $('tr tr').filter(function () { return $('td input:checkbox:checked', this).length }).each(function () {
                    total_cost = total_cost + ($('td input:text', this).val() * $('span[id$="LblPrice"]', this).text());
                })

                $('#<%= LblTotalPriceContent.ClientID  %>').html(total_cost);
                $('#<%= HideTotalPrice.ClientID  %>').val(total_cost);

            });

        });
    </script>    


</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    Edit Order
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
    Edit Order
</asp:Content>
